/*
Created on Sept. 28th 2005
(C) 2005 
@author Michael J Ocean

This program is free software; you can redistribute it and/or
modify it under the terms of Version 2 of the GNU General Public 
License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

package sxe.sensors;

import java.util.Hashtable;
import java.util.Vector;

import javax.media.*;
import javax.media.format.VideoFormat;


public class ImageSensorDetector {

	public ImageSensorDetector() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	static public Hashtable<String, GenericSensor> detect(){
		Hashtable<String, GenericSensor> ht = new Hashtable<String, GenericSensor>();

		Vector vDevs = null;
		try{
			vDevs = CaptureDeviceManager.getDeviceList(null);	
		}
		catch(NoClassDefFoundError ex){
			System.err.println("The JMF.jar was not properly set in the CLASSPATH\nSensors requiring JMF (e.g., Video) will be unavailable from this SXE.");
			return ht;
		}
		
		CaptureDeviceInfo deviceInfo;
		boolean bIsVideoDev; 
		
		for(int i=0;i<vDevs.size();i++){
			deviceInfo = (CaptureDeviceInfo)vDevs.elementAt(i);
			bIsVideoDev = false;
			Format deviceFormat[] = deviceInfo.getFormats();
			for (int j = 0; j < deviceFormat.length; j++)
			{
				if (deviceFormat[j] instanceof VideoFormat){
					bIsVideoDev = true;
				}
			}
			if(bIsVideoDev){
				ImageSensor is = new ImageSensor(deviceInfo);
				ht.put(is.getID(),is);
				if(!is.initializeSensor())
					System.err.println("ImageSensor " + is.m_id + " failed to initialize.");
			}
		}
		return ht;
	}
}
